//
// Author    : Pablo Bosch 
// Contact   : pboschvivancos@epo.org
// Last Modif: 13/03/2005
//

var MOD_CLB={
  impver:1
};


MOD_CLB.updateEq=function(cl) {
  changeEq(cl,document.getElementById("tabe_"+cl).value);
}

MOD_CLB.updateDep=function(cl) {
  var dep=document.getElementById("tabd_"+cl).value;
  if(dep && cl==dep) {
    alert("Error: Circular dependence, claim "+cl+" depends on claim "+dep);
    document.getElementById("tabd_"+cl).value=GetClaimDep(cl); // restore
    return;
  }
  if(dep > cl) {
    alert("Warning : Weird dependence, claim "+cl+"depends on claim "+dep);
  }
  SetClaimDep(cl,dep);
  dep=GetClaimDep(cl); // beautify 
  document.getElementById("tabd_"+cl).value=dep;

  var stab=document.getElementById("subtab"+cl);
  if(stab){  
    stab.className=cltypename(dep);  
  } else {
    alert("subtab"+cl+" not found");
  }
  
}


// import claim info from previous claimsets



MOD_CLB.climport=function(cl,icl,ver) {
  import_claim(cl,icl,ver);
  //alert("Claim "+cl+" import from "+icl+" version"+ver);
  document.getElementById("tabi_"+cl).value=GetClaimImport(cl); // beautify 
}


function cltable() {
  var CLNUM= GetClaimSetLength(); 
  var nu = GetGroupsLength();
  var cl=0;
  var NVERS    = GetClaimSetVersion();
  if(NVERS>1) {
    MOD_CLB.impver   =html_selected_iter("impver",MOD_CLB.impver);
  } 
  CURRENTVIEW="claimtable";
  // table header 
  var html="<TABLE CLASS=CLTAB border=1><TR><TH>CL</TH>";
  for(var i=0; i< 10 && i<=CLNUM; i++) {
    html+="<TH>" + i + "</TH>";
  }
  html+="</TR>";  
  
  // table body
  var eq,dep,mclass;
  var row=0;
  var html_row;
  while(cl<= CLNUM) {
    html_row="<TR><TH>"+row+"</TH>";	
    for(col=0; col<10 && cl<= CLNUM; col++,cl++) {      
      if(IsClaimInFilter(cl)) { 
	dep=GetClaimDep(cl);
	eq=GetClaimEq(cl);
	if(claim_isgrpindependent(dep)) {
	  mclass="CLASS='CLINDEP"+cltypeshortname(dep)+"'";
	} else {
	  mclass="CLASS='CLDEP"+cltypeshortname(dep)+"'";
	}
      } else {
	mclass="CLASS='HIDEN'" ;
      }
      
      html_row+="<TD><TABLE "+mclass+" id='subtab"+cl+"'>";
      if(nu > 1 && cl>0) {
	html_row+="<TR><TD align=center>G </TD><TD align=center> "+ group_select(cl)+  "</TD></TR>";
      }
      html_row+="<TR><TD align=center>D</TD><TD align=right>";
      html_row+="<input type=text name='D' size=3 value='" + dep + "' tabindex='" + cl + "' id='tabd_"+cl+"' ";
      html_row+="  onChange='MOD_CLB.updateDep("+cl+");'></TD></TR>";
      
      html_row+="<TR><TD align=center>E</TD><TD align=right>";
      html_row+="<input type=text name=E size=3 value='" + eq + "' tabindex='" + (CLNUM + cl) + "' id='tabe_"+cl+"' "; 
      html_row+="  onChange='MOD_CLB.updateEq("+cl+");'></TD></TR>";
      
      if(NVERS>1 && cl>0) {
	html_row+="<TR><TD align=center>I</TD><TD align=right>";
	html_row+="<input type=text name=M size=3 value='" + GetClaimImport(cl) + "' id='tabi_"+cl+"'  onChange='MOD_CLB.climport("+cl+",this.value"+","+MOD_CLB.impver+");'></TD></TR>";
	html_row+="</TD></TR>";
      }
      html_row+="</TABLE></TD>";
    }
    html+=html_row;
    row++;
  }	
  html+="</TABLE>";
  return html;
}
